package cn.lsc.web.controller;

import cn.lsc.result.JSONResult;
import cn.lsc.service.IVerifyCodeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/*
* 图形验证码接口
* */
@RequestMapping("/verifycode")
@RestController
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult getVerifyCode(@PathVariable(value = "imageCodeKey") String imageCodeKey){
        try {
            String baseStr=iVerifyCodeService.getVerifyCode(imageCodeKey);
            return JSONResult.success().setData(baseStr);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.error();
        }
    }
    @GetMapping("/Recommendationcode/{userId}")
    public JSONResult RecommendationCode(@PathVariable(value = "userId") Long userId){
        return iVerifyCodeService.RecommendationCode(userId);
    }


    @PostMapping("/sendSmsCode")
    public JSONResult smsCode(@RequestBody Map<String,String> map){
        try {
            iVerifyCodeService.smsCode(map);
            return JSONResult.success();
        }  catch (Exception e) {
            e.printStackTrace();
            return JSONResult.error();
        }
    }
    @PostMapping("/binderSmsCode")
    public JSONResult binderSmsCode(@RequestBody Map<String,String> map){
        try {
            iVerifyCodeService.binderSmsCode(map);
            return JSONResult.success();
        }  catch (Exception e) {
            e.printStackTrace();
            return JSONResult.error();
        }
        }
    }


